<template>
	<view class="sign_in">
		<image class="background" src="@/static/images/sign_background.jpg" mode="widthFix"></image>
		<view class="main">
			<view class="title">忘记密码</view>
			<view class="input">
				<u-input v-model="phone" type="number" placeholder='请输入手机号' />
			</view>
			<view class="input_pass">
				<view class="pass">
					<u-input v-model="code" type="text" :clearable='false' placeholder='请输入验证码' />
				</view>
				<text class="btn" @click="sendCodeBtn">{{codeTxt}}</text>
			</view>
			<view class="input">
				<u-input v-model="pass" type="password" placeholder='请输入8-16位数字、英文组合密码' />
			</view>
			<view class="input">
				<u-input v-model="pass_two" type="password" placeholder='请再次输入8-16位数字、英文组合密码' />
			</view>
			<view class="in_btn" @click="submitBtn">确认</view>
			<view class="bot_txt" @click="siginBtn">登录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				code:'',
				pass:'',
				pass_two:'',
				// 
				disabled:false,
				codeTxt:'发送验证码',
				sendTime:60,
				time:null,
			};
		},
		methods:{
			// 发送验证码
			sendCodeBtn(){
				var that = this
				if(that.disabled){
					return
				}
				if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
					that.$tips.showToast('请输入正确的手机号')
					return
				}else{
					that.$tips.showLoading('发送中')
					var params = {
						mobile:that.phone,
						event:'resetpwd'
					}
					that.$httpApi.smsSend(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							if (!that.timer) {
							  that.disabled = true
							  that.codeTxt = that.sendTime+'s'
							  that.timer = setInterval(() => {
							    if (that.sendTime > 0 && that.sendTime <= 60) {
							      that.sendTime--
							      that.codeTxt = that.sendTime+'s'
							    } else {
							      that.disabled = false
							      that.sendTime = 60
							      that.codeTxt = '重新获取'
							      clearInterval(that.timer)
							      that.timer = null;
							    }
							  }, 1000)
							}
						}
					})
				}
			},
			submitBtn(){
				var that = this
				if(that.phone=='' || !that.$test.phoneTrue(that.phone)){
					that.$tips.showToast('请输入正确的手机号')
					return
				}else if(that.code==''){
					that.$tips.showToast('请输入验证码')
					return
				}else if(that.pass==''){
					that.$tips.showToast('请输入密码')
					return
				}else if(that.pass.length<8){
					that.$tips.showToast('密码格式不正确')
					return
				}else if(that.pass_two==''){
					that.$tips.showToast('请再次输入密码')
					return
				}else if(that.pass!=that.pass_two){
					that.$tips.showToast('密码不一致')
					return
				}else{
					that.$tips.showLoading('加载中')
					var params = {
						mobile:that.phone,
						captcha:that.code,
						newpassword:that.pass,
						newpassword_tow:that.pass_two,
					}
					that.$httpApi.userResetpwd(params).then((res)=>{
						that.$tips.hideLoading()
						if(res.code==1){
							that.$tips.showToast('修改成功')
							setTimeout(function(){
								uni.reLaunch({
									url:'/pages/signIn/sign_in'
								})
							},2000)
						}
					})
				}
			},
			// 登录
			siginBtn(){
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="less">
	.sign_in{
		width: 100%;
		height: 100vh;
		.background{
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1;
			display: block;
			width: 100%;
			height: 100%;
		}
		.main{
			position: relative;
			z-index: 2;
			width: 100%;
			padding: 200rpx 65rpx 50rpx;
			.title{
				width: 100%;
				font-size: 64rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: 500;
				color: #26C281;
				padding-bottom: 100rpx;
			}
			.input{
				width: 100%;
				height: 80rpx;
				margin-top: 40rpx;
				border-bottom: 1rpx solid rgba(190, 190, 190, 0.2);
				::v-deep .u-input__input{
					font-size: 32rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}
			}
			.input_pass{
				width: 100%;
				height: 80rpx;
				margin-top: 40rpx;
				border-bottom: 1rpx solid rgba(190, 190, 190, 0.2);
				display: flex;
				align-items: center;
				justify-content: space-between;
				.pass{
					width: calc(100% - 160rpx);
					::v-deep .u-input__input{
						font-size: 32rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
				.btn{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #26C281;
				}
			}
			.in_btn{
				margin-top: 100rpx;
				width: 100%;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				background: #26C281;
				border-radius: 44rpx;
			}
			.bot_txt{
				width: 100%;
				margin-top: 100rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #26C281;
			}
		}
	}
</style>
